package com.xmg.p2p.base.service.impl;

import com.xmg.p2p.base.domain.SystemDictionaryItem;
import com.xmg.p2p.base.mapper.SystemDictionaryItemMapper;
import com.xmg.p2p.base.query.PageResult;
import com.xmg.p2p.base.query.SystemDictionaryQueryObject;
import com.xmg.p2p.base.service.ISystemDictionaryItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * lcd  2020/5/14
 * Description:
 */
@Service
public class SystemDictionaryItemServiceImpl implements ISystemDictionaryItemService {
    @Autowired
    private SystemDictionaryItemMapper systemDictionaryItemMapper;

    @Override
    public PageResult queryForPage(SystemDictionaryQueryObject qo) {
        int i = systemDictionaryItemMapper.queryForCount(qo);
        if (i > 0) {
            List<SystemDictionaryItem> items = systemDictionaryItemMapper.queryForPage(qo);
            return new PageResult(items,i,qo.getCurrentPage(),qo.getPageSize());
        }else{
            return PageResult.empty(qo.getPageSize());
        }

    }

    @Override
    public void saveOrUpdate(SystemDictionaryItem dictionaryItem) {
        if (dictionaryItem.getId() == null) {
            systemDictionaryItemMapper.insert(dictionaryItem);
        }else {
            systemDictionaryItemMapper.updateByPrimaryKey(dictionaryItem);
        }
    }

    @Override
    public List<SystemDictionaryItem> queryBySn(String sn) {
        return systemDictionaryItemMapper.queryBySn(sn);
    }
}
